package _thread_lock._threadexception;

/**
 * @Author: huangya
 * @Date: 2020/10/14
 * @Description:
 */
public class ThreadExceptionTest2 {

    public static void main(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                int i = 1 / 0;//发生异常
            }
        });
        //自定义未捕获异常处理器
        thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread t, Throwable e) {
                System.out.println("尝试捕获线程抛出的异常！");
            }
        });
        thread.start();
    }
}
